package com.wanli.agent.homepage;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.wanli.agent.R;
import com.wanli.agent.base.BaseActivity;
import com.wanli.agent.base.DataCallBack;
import com.wanli.agent.bean.StoreStatisticsBean;
import com.wanli.agent.bean.UserInfoBean;
import com.wanli.agent.homepage.model.HomePageModelImpl;
import com.wanli.agent.homepage.model.IHomePageModel;
import com.wanli.agent.utils.SPManager;
import com.wanli.agent.widget.AppTitleBar;
import com.wanli.agent.widget.ViewLoading;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 商户列表
 */
public class MerchantListActivity extends BaseActivity {


    @BindView(R.id.title_bar)
    AppTitleBar titleBar;
    @BindView(R.id.tv_total_store)
    TextView tvTotalStore;
    @BindView(R.id.tv_total_store_remark)
    TextView tvTotalStoreRemark;
    @BindView(R.id.ll_root_total_store)
    LinearLayout llRootTotalStore;
    @BindView(R.id.tv_high_quality_store)
    TextView tvHighQualityStore;
    @BindView(R.id.tv_high_quality_store_remark)
    TextView tvHighQualityStoreRemark;
    @BindView(R.id.ll_root_high_quality_store)
    LinearLayout llRootHighQualityStore;
    @BindView(R.id.tv_normal_quality_store)
    TextView tvNormalQualityStore;
    @BindView(R.id.tv_normal_quality_store_remark)
    TextView tvNormalQualityStoreRemark;
    @BindView(R.id.ll_root_normal_quality_store)
    LinearLayout llRootNormalQualityStore;
    @BindView(R.id.tv_silent_store)
    TextView tvSilentStore;
    @BindView(R.id.tv_silent_store_remark)
    TextView tvSilentStoreRemark;
    @BindView(R.id.ll_root_silent_store)
    LinearLayout llRootSilentStore;
    @BindView(R.id.tv_new_store)
    TextView tvNewStore;
    @BindView(R.id.tv_new_store_remark)
    TextView tvNewStoreRemark;
    @BindView(R.id.ll_root_new_store)
    LinearLayout llRootNewStore;
    @BindView(R.id.tv_approved)
    TextView tvApproved;
    @BindView(R.id.tv_approved_remark)
    TextView tvApprovedRemark;
    @BindView(R.id.ll_root_approved)
    LinearLayout llRootApproved;
    @BindView(R.id.tv_not_approved)
    TextView tvNotApproved;
    @BindView(R.id.tv_not_approved_remark)
    TextView tvNotApprovedRemark;
    @BindView(R.id.ll_root_not_approved)
    LinearLayout llRootNotApproved;
    @BindView(R.id.tv_waiting_for_income)
    TextView tvWaitingForIncome;
    @BindView(R.id.tv_waiting_for_income_remark)
    TextView tvWaitingForIncomeRemark;
    @BindView(R.id.ll_waiting_for_income)
    LinearLayout llWaitingForIncome;
    private IHomePageModel homePageModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_merchant_list);
        ButterKnife.bind(this);
        initView();
        initData();
    }

    private void initView() {
        UserInfoBean userInfoBean = new Gson().fromJson(SPManager.getInstance().getUserInfoJson(), UserInfoBean.class);
        if (userInfoBean != null) {
            if (userInfoBean.getData().getId() == 1) {
                llRootSilentStore.setVisibility(View.VISIBLE);
            } else {
                llRootSilentStore.setVisibility(View.GONE);
            }
        }
    }

    private void initData() {
        homePageModel = new HomePageModelImpl();
        requestGetStoreStatistics();
    }

    public void requestGetStoreStatistics() {
        ViewLoading.showProgress(mActivity);
        homePageModel.requestGetStoreStatistics(new DataCallBack<StoreStatisticsBean>() {
            @Override
            public void onSuccessful(StoreStatisticsBean bean) {
                tvTotalStore.setText(bean.getData().getAll_store_count());
                tvNewStore.setText(bean.getData().getNew_store_count());
                tvHighQualityStore.setText(bean.getData().getHigh_quality_store_count());
                tvNormalQualityStore.setText(bean.getData().getNormal_quality_store_count());
                tvSilentStore.setText(bean.getData().getSilent_store_count());
                tvApproved.setText(bean.getData().getChecking_store_count());
                tvNotApproved.setText(bean.getData().getUn_pass_store_count());
                tvWaitingForIncome.setText(bean.getData().getWaiting_for_income_profile_count());

                tvTotalStoreRemark.setText(bean.getData().getAll_store_count_remark());
                tvNewStoreRemark.setText(bean.getData().getNew_store_count_remark());
                tvHighQualityStoreRemark.setText(bean.getData().getHigh_quality_store_count_remark());
                tvNormalQualityStoreRemark.setText(bean.getData().getNormal_quality_store_count_remark());
                tvSilentStoreRemark.setText(bean.getData().getSilent_store_count_remark());
                tvNotApprovedRemark.setText(bean.getData().getUn_pass_store_count_remark());
                tvApprovedRemark.setText(bean.getData().getChecking_store_count_remark());
                tvWaitingForIncomeRemark.setText(bean.getData().getWaiting_for_income_profile_count_remark());
            }

            @Override
            public void onFailed(String msg, String code) {

            }
        });
    }


    @OnClick({R.id.ll_root_total_store,
            R.id.ll_root_new_store, R.id.ll_root_high_quality_store,
            R.id.ll_root_normal_quality_store, R.id.ll_root_silent_store,
            R.id.ll_root_approved, R.id.ll_root_not_approved, R.id.ll_waiting_for_income})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_root_total_store:
                Intent intent = new Intent(mActivity, MerchantDetailsListActivity.class);
                intent.putExtra("type", "all_store_count");
                startActivity(intent);
                break;
            case R.id.ll_root_new_store:
                intent = new Intent(mActivity, MerchantDetailsListActivity.class);
                intent.putExtra("type", "new_store_count");
                startActivity(intent);
                break;
            case R.id.ll_root_high_quality_store:
                intent = new Intent(mActivity, MerchantDetailsListActivity.class);
                intent.putExtra("type", "high_quality_store_count");
                startActivity(intent);
                break;
            case R.id.ll_root_normal_quality_store:
                intent = new Intent(mActivity, MerchantDetailsListActivity.class);
                intent.putExtra("type", "normal_quality_store_count");
                startActivity(intent);
                break;
            case R.id.ll_root_silent_store:
                intent = new Intent(mActivity, MerchantDetailsListActivity.class);
                intent.putExtra("type", "silent_store_count");
                startActivity(intent);
                break;
            case R.id.ll_root_approved:
                intent = new Intent(mActivity, MerchantDetailsListActivity.class);
                intent.putExtra("type", "checking_store_count");
                startActivity(intent);
                break;
            case R.id.ll_root_not_approved:
                intent = new Intent(mActivity, MerchantDetailsListActivity.class);
                intent.putExtra("type", "un_pass_store_count");
                startActivity(intent);
                break;
            case R.id.ll_waiting_for_income:
                intent = new Intent(mActivity, MerchantDetailsListActivity.class);
                intent.putExtra("type", "waiting_for_income_profile_count");
                startActivity(intent);
                break;
        }
    }
}
